package com.yonyou.iuap.ipaas.connector.sdwcoatencent;


import cn.hutool.json.JSONUtil;
import com.yonyou.iuap.ipaas.connector.sdk.api.model.ConnectorParams;
import com.yonyou.iuap.ipaas.connector.sdk.api.model.ResponseAttributes;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.business.dept.BipDept;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.business.msg.extend.BipTodo;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.business.staff.BaseUser;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.internal.SdwcoatencentConnection;
import com.yonyou.yonlinker.ysb.runtime.extension.api.runtime.operation.Result;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;

/**
 * ** description 描述 **
 * 测试类
 */
public class SdwcoatencentOperationsTestCase {
	
	private static Logger logger = LoggerFactory.getLogger(SdwcoatencentOperationsTestCase.class);
	
	private SdwcoatencentConnection connection;
	public static final String openApiHost = "https://qyapi.weixin.qq.com";
	public static final String agentid = "1000002";
	public static final String corpid = "ww9eaeb35c67594030";
	public static final String appCorpsecret = "f7wlzss-1kKyBHMLKM7TUoI8FLdyYtRxJg7tg2D1XeM";
	public static final String connectCorpsecret = "bwKM55Apb3JNzFjZXPYB1Pyq33oZj-5tibay1oaYZh0";
	public static final String authHost = "https://open.weixin.qq.com";
	public static final String httpTimeOut = "300000";
	public static final String authInterface = "http://alyscloud.com/saas-oa-daily/auth/qiyewechat";
	

	
	@Before
	public void before() {
		ConnectorParams connectorParams = new ConnectorParams();
		HashMap<String, String> paramMap = new HashMap<>();
		paramMap.put("agentid", agentid);
		paramMap.put("corpid", corpid);
		paramMap.put("host", openApiHost);
		paramMap.put("appCorpsecret", appCorpsecret);
		paramMap.put("connectCorpsecret", connectCorpsecret);
		paramMap.put("httpTimeOut", httpTimeOut);
		paramMap.put("authInterface", authInterface);
		paramMap.put("authHost", authHost);
		connectorParams.setParams(paramMap);
		this.connection = new SdwcoatencentConnection(connectorParams);
		connection.validate();
	}
	public static void main(String[] args) {
		System.out.println(111);
	}
/*

	*/
/**
	 * 批量新增用户
	 *//*

	@Test
	public void batchSaveUser() {
		String userStr="[{\"enable\":false,\"mobile\":\"+86-13943879320\",\"email\":\"121@163.com\",\"sourceSys\":\"YonLinker_bip_tencent_staffbinding\",\"sourceUnique\":\"0e355b3d-7e6a-462d-963e-15a95e4a2e08\"}]";
		List<BaseUser> bipUsers = JSONUtil.toList(userStr, BaseUser.class);
		Result<String, ResponseAttributes> res = userOperations.queryUserIds(connection, bipUsers);
		System.out.println(JSONUtil.toJsonStr(res));
	}


	*/
/**
	 * 批量新增部门
	 *//*

	@Test
	public void batchSaveDept() {
		BipDept bipDept = new BipDept();
		bipDept.setId(3L);
		bipDept.setName("艾雷企微测试3");
		bipDept.setSourceUnique("2085930616436555777");
		bipDept.setCode("AL001");
		ArrayList<BipDept> depts = new ArrayList<>();
		depts.add(bipDept);
		Result<String, ResponseAttributes> res = deptOperations.batchSaveOrUpdateDept(connection, depts);
		System.out.println(JSONUtil.toJsonStr(res));
	}

	@Test
	public void msgSave() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
		//woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q
		String msggStr="[{\"executorIdsList\":[\"woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q\"],\"webUrl\":\"https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&apptype=mdf&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&from_mc_workflow=1&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform\",\"mUrl\":\"https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&apptype=mdf&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&systemCode=&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform\",\"commitUserId\":\"woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q\",\"msgTitle\":\"销售订单+xz+000031\",\"msgContent\":\"+xz+000031\\n档案：\\n文本：\",\"yyUserIds\":[\"e36964aa-d958-4981-bcea-a1f75b340df3\"],\"syncFlag\":true,\"tenantId\":\"0000LC5NLRD4GPBAR40000\",\"sourceUnique\":\"5c213fd4-70bc-11ef-adcb-f6c30d5d6c52\",\"needBusinessData\":false}]";
		List<BipTodo> bootMessageBeans = JSONUtil.toList(msggStr, BipTodo.class);
		Result<String, ResponseAttributes> res = botMsgOperations.sendBotMsg(connection, bootMessageBeans);
		System.out.println(JSONUtil.toJsonStr(res));
//		String urlStr="http://alyscloud.com/saas-oa-daily/auth/qiyewechat/0000LC5NLRD4GPBAR40000/woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q?webUrl=https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&apptype=mdf&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&from_mc_workflow=1&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform&mUrl=https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&apptype=mdf&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&systemCode=&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform";
////
//		System.out.println(urlStr.length());
	}

	@Test
	public void delSave() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
		//woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q
		String msggStr="[{\"agentMsgId\":\"woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q\",\"syncFlag\":true,\"msgid\":\"rLJmrcznZe60JWv44lmLYgDBqFTxXVxjWBzhX_l3s9s\",\"tenantId\":\"0000LC5NLRD4GPBAR40000\",\"sourceUnique\":\"2b8e8b1e-7683-11ef-8d23-5aed6a3d7efc\",\"needBusinessData\":false}]";
		List<BipTodo> bootMessageBeans = JSONUtil.toList(msggStr, BipTodo.class);
		Result<String, ResponseAttributes> res = botMsgOperations.sendUpdateBotMsg(connection, bootMessageBeans);
		System.out.println(JSONUtil.toJsonStr(res));
//		String urlStr="http://alyscloud.com/saas-oa-daily/auth/qiyewechat/0000LC5NLRD4GPBAR40000/woZSeDNAAAvhSCvfjzeRLZ4qfMBmsu4Q?webUrl=https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&apptype=mdf&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&from_mc_workflow=1&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform&mUrl=https://bip-daily.yonyoucloud.com/mdf-node/meta/voucher/voucher_order/2086615088198844418?domainKey=udinghuo&apptype=mdf&businessStepCode=&tenantId=0000LC5NLRD4GPBAR40000&serviceCode=orderList&taskId=5c213fd4-70bc-11ef-adcb-f6c30d5d6c52&systemCode=&from_service=iuap-apcom-messagecenter&adt=wf&url_actual_build_source=iuap-apcom-messageplatform";
////
//		System.out.println(urlStr.length());
	}
*/


	/*public static void main(String[] args) throws Exception {
		String appId = "xxx";

		Map<String, Object> queryParam = new HashMap<>();
		queryParam.put("timestamp", 1639734344);
		queryParam.put("access_token", "59cf5437-669b-49f5-83c4-3cc1d1404680");
		queryParam.put("app_key", appId);

		String sign = ApiSign.sign(queryParam, appId);
		queryParam.put("sign", sign);

		HttpRequest<Object> build = HttpRequest.builder(Object.class)
				.method(HttpMethod.GET)
				.endpoint("xxxx")
				.path("erp/sc/data/local_inventory/brand")
				.queryParams(queryParam)
				.build();
		HttpResponse execute = HttpExecutor.create().execute(build);
		log.info("execute:{}", execute.readEntity(Object.class));
	}*/




}
